package com.zhou.kotlin_car_data_list.adapter

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.zhou.kotlin_car_data_list.R
import com.zhou.kotlin_car_data_list.bean.Model
import com.zhou.kotlin_car_data_list.databinding.ItemModelCarListBinding

/**
 * </br>
 * Date: 2025/8/27
 * Created by:zhourui
 */
class ModelCarListAdapter(var context: Context, var mData: MutableList<Model>) :
    RecyclerView.Adapter<ModelCarListAdapter.ModelCarListHolder>() {

    var inflater = LayoutInflater.from(context)

    class ModelCarListHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        var binding: ItemModelCarListBinding? = null
    }

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ModelCarListHolder {
        val binding: ItemModelCarListBinding =
            DataBindingUtil.inflate(inflater, R.layout.item_model_car_list, parent, false)
        val holder = ModelCarListHolder(binding.root)
        holder.binding = binding
        return holder
    }

    override fun getItemCount(): Int {
        return mData.size
    }

    override fun onBindViewHolder(holder: ModelCarListHolder, position: Int) {
        val model = mData[position]
        holder.binding?.modelCarListItem = model
    }
}